<template>
  <div class="my">
    <div class="my_info" @click="_goMyInfo">
      <div class="img-box">
        <img v-if="user.Head" :src="base + user.Head" alt="" />
        <img v-else src="@/assets/Images/AppIcon/common_default_header.png" alt="" />
      </div>
      <div class="info_box">
        <div class="mb-10" style="font-size: 16px; color: #333">
          {{ user.ChnName }}
        </div>
        <div class="mb-10">
          {{ getCompanyName(user) }}
        </div>
        <div v-if="user.OrgName">
          {{ user.OrgName }} {{ user.PostName ? "|" + user.PostName : "" }}
        </div>
      </div>
      <div>
        <img
          style="height: 15px; width: 15px"
          src="@/assets/Images/AppIcon/icon_arrow_right.png"
          alt=""
        />
      </div>
    </div>
    <div class="about_box">
      <div class="mb-30" @click="_goAbout">
        <img src="@/assets/icons/icon_nav_home_on.png" alt="" />
        <div class="text">关于{{ prorgram }}</div>
        <img src="@/assets/Images/AppIcon/icon_arrow_right.png" alt="" />
      </div>
      <div  @click="_goProblem">
        <img src="@/assets/icons/icon_nav_home_on.png" alt="" />
        <div class="text">问题反馈</div>
        <img src="@/assets/Images/AppIcon/icon_arrow_right.png" alt="" />
      </div>
      <div  class="mt-30" @click="_goPolicy">
        <img src="@/assets/icons/icon_nav_home_on.png" alt="" />
        <div class="text">隐私政策</div>
        <img src="@/assets/Images/AppIcon/icon_arrow_right.png" alt="" />
      </div>
    </div>
    <div style="margin: 20px">
      <van-button block type="info" @click="_logOut"> 退出登录 </van-button>
    </div>
    <Tabbar :showSnapshot="showSnapshot" />
  </div>
</template>

<script>
import Tabbar from "@/components/Tabbar.vue";
import { logout} from "@/api/public";
import { mapGetters } from "vuex";
import { Dialog } from "vant";
export default {
  components: {
    Tabbar,
  },
  data() {
    return {
      showSnapshot:
        this.$store.state.companySysType == "RA" ||
        this.$store.state.companySysType == "JT",
      user: {},
      prorgram: process.env.VUE_APP_TITLE,
      base: process.env.VUE_APP_BASE_API,
    };
  },
  computed: {
    ...mapGetters(["baseUrl"]),
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      let url = "/UserUser/GetMyInfo"; // /api/goods
      this.$axios
        .get(url)
        .then((res) => {
          this.user = res.data;
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
    // 个人信息
    _goMyInfo() {
      this.$router.push("/Home/My/info?userName=" + this.user.ChnName);
    },
    // 关于
    _goAbout() {
      this.$router.push("/Home/My/About");
    },
    // 问题反馈
    _goProblem() {
      this.$router.push("/Home/My/Problem");
    },
    _logOut() {
      Dialog.confirm({
        title: "询问",
        message: "您确定要退出登录吗?",
      })
        .then(() => {
          // on confirm
          logout().then((res) => {
            this.$router.push("/login");
          });
        })
    },
    _goPolicy(){
      this.$router.push("/Home/My/policy");
    },
    getCompanyName(user){
       if(user.OrgCode){
         if(user.OrgCode.startsWith('O:')){
            return user.OrgCode.substring(2);
         }
         return user.CompanyName;
       }
       return user.CompanyName;
    }
  },
};
</script>

<style lang="less" scoped>
.my {
  height: 100vh;
  background-color: #e8f1f8;
  font-size: 14px;
}
.my_info {
  display: flex;
  padding: 20px;
  align-items: center;
  justify-content: space-between;
  background-color: #fff;
  margin-bottom: 10px;
  img {
    height: 50px;
    width: 50px;
    border-radius: 50%;
  }
  .info_box {
    width: 220px;
    color: #999;
  }
}
.about_box {
  padding: 20px;
  background-color: #fff;
  > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .text {
      width: 300px;
      margin-left: 10px;
    }
  }
  img {
    height: 15px;
    width: 15px;
  }
}
</style>
